home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / ObjectTcl-1.1 / OtclAttribute.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  6.3 KB  |  174 lines

  1. /*  _ __ ___ _
  2.  * | |\ /  /| |  $Id: OtclAttribute.C,v 1.6 1995/05/09 16:14:20 deans Exp $
  3.  * | | /  / | |  Copyright (C) 1995 IXI Limited.
  4.  * |_|/__/_\|_|  IXI Limited, Cambridge, England.
  5.  *
  6.  * Component   : OtclAttribute.C
  7.  *
  8.  * Author      : Dean Sheehan (deans@x.co.uk)
  9.  *
  10.  * Description : Contains the implementation of OtclAttribute and 
  11.  *               OtclAttributeTemplate classes that model attributes on classes
  12.  *               in Object Tcl.
  13.  *
  14.  * License     :
  15.             Object Tcl License & Copyright
  16.             ------------------------------
  17.  
  18. IXI Object Tcl software, both binary and source (hereafter, Software) is copyrighted by IXI Limited (IXI), and ownership remains with IXI. 
  19.  
  20. IXI grants you (herafter, Licensee) a license to use the Software for academic, research and internal business purposes only, without a fee. Licensee may distribute the binary and source code (if required) to third parties provided that the copyright notice and this statement appears on all copies and that no charge is associated with such copies. 
  21.  
  22. Licensee may make derivative works. However, if Licensee distributes any derivative work based on or derived from the Software, then Licensee will (1) notify IXI regarding its distribution of the derivative work, and (2) clearly notify users that such derivative work is a modified version and not the original IXI Object Tcl distributed by IXI. IXI strongly recommends that Licensee provide IXI the right to incorporate such modifications into future releases of the Software under these license terms. 
  23.  
  24. Any Licensee wishing to make commercial use of the Software should contact IXI, to negotiate an appropriate license for such commercial use. Commercial use includes (1) integration of all or part of the source code into a product for sale or license by or on behalf of Licensee to third parties, or (2) distribution of the binary code or source code to third parties that need it to utilize a commercial product sold or licensed by or on behalf of Licensee. 
  25.  
  26. IXI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. IXI SHALL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER SUFFERED BY THE USERS OF THIS SOFTWARE. 
  27.  
  28. Copyright (C) 1995, IXI Limited 
  29.  
  30. By using or copying this Software, Licensee agrees to abide by the copyright law and all other applicable laws of England and the U.S., including, but not limited to, export control laws, and the terms of this license. IXI shall have the right to terminate this license immediately by written notice upon Licensee's breach of, or non-compliance with, any of its terms. Licensee may be held legally responsible for any copyright infringement that is caused or encouraged by Licensee's failure to abide by the terms of this license. 
  31.  
  32. Comments and questions are welcome and can be sent to
  33. otcl@x.co.uk 
  34.  
  35. For more information on copyright and licensing issues, contact: 
  36. Legal Department, IXI Limited, Vision Park, Cambridge CB4 4ZR,
  37. ENGLAND. 
  38.  
  39.  *
  40.  */
  41.  
  42. // Tcl Includes
  43. #include <tclInt.h>
  44.  
  45. // Local Includes
  46. #include "Otcl.H"
  47. #include "OtclAttribute.H"
  48.  
  49.  
  50. // Constructor for OtclAttribute class.
  51. // hashEntry is the Tcl_HashEntry * that this attribute is owned bye.
  52. OtclAttribute::OtclAttribute (Tcl_HashEntry *hashEntry, int isArray,
  53.                               char *initialiser, Tcl_Interp *interp)
  54. {
  55.    var = new Var;
  56.    var->flags = (isArray == OTCL_TRUE) ? VAR_ARRAY : 0;
  57.    var->searchPtr = NULL;
  58.    var->tracePtr = NULL;
  59.    var->refCount = 0;
  60.    var->hPtr = hashEntry;
  61.  
  62.    if (isArray)
  63.    {
  64.       var->value.tablePtr = new Tcl_HashTable;
  65.       Tcl_InitHashTable(var->value.tablePtr,TCL_STRING_KEYS);
  66.  
  67.       if (initialiser != NULL)
  68.       {
  69.          // break initialiser down into list of pairs
  70.          int argc;
  71.          char **argv;
  72.          if (Tcl_SplitList(interp,initialiser,&argc,&argv) == TCL_OK)
  73.          {
  74.             int innerArgc;
  75.             char **innerArgv;
  76.             Var *v;
  77.             int newEntry;
  78.             Tcl_HashEntry *hentry;
  79.             for (int index = 0; index < argc; index++)
  80.             {
  81.                if (Tcl_SplitList(interp,argv[index],&innerArgc,&innerArgv) ==
  82.                    TCL_OK)
  83.                {
  84.                   if (innerArgc == 2)
  85.                   {
  86.                      v = new Var;
  87.                      hentry = Tcl_CreateHashEntry(var->value.tablePtr,
  88.                                                   innerArgv[0],
  89.                                                   &newEntry);
  90.                      if (newEntry)
  91.                      {
  92.                         Tcl_SetHashValue(hentry,v);
  93.                      }    
  94.                      else
  95.                      {
  96.                         free((char*)v->value.string);
  97.                         delete v;
  98.                      }
  99.                      v->flags = 0;
  100.                      v->searchPtr = NULL;
  101.                      v->tracePtr = NULL;
  102.                      v->refCount = 0;
  103.                      v->hPtr = hentry;
  104.                      v->valueLength = strlen(innerArgv[1]);
  105.                      v->value.string = strdup(innerArgv[1]);
  106.                      v->valueSpace = v->valueLength;
  107.          
  108.                   }
  109.                   free((char*)innerArgv);
  110.                }
  111.             }
  112.             free((char*)argv);
  113.          }
  114.       }
  115.    }  
  116.    else
  117.    {
  118.       if (initialiser == NULL)
  119.       {
  120.          var->valueLength = 1;  
  121.          var->value.string = strdup("");
  122.       }
  123.       else
  124.       {
  125.          var->valueLength = strlen(initialiser);
  126.          var->value.string = strdup(initialiser);
  127.       }
  128.       var->valueSpace = var->valueLength;
  129.    } 
  130. }
  131.  
  132. OtclAttribute::~OtclAttribute ()
  133. {
  134.     if (var->valueSpace != 0)
  135.     {
  136.        free(var->value.string);
  137.        var->valueSpace = 0;
  138.        var->valueLength = 0;
  139.     }
  140.     delete var;
  141. }
  142.  
  143. OtclAttribute::operator Var * ()
  144. {
  145.    return var;
  146. }
  147.  
  148. OtclAttributeTemplate::OtclAttributeTemplate (Tcl_Interp *, int array, char *i)
  149. {
  150.    if (i == NULL)
  151.    {
  152.       initialiser = NULL;
  153.    }
  154.    else
  155.    {
  156.       initialiser = strdup(i);
  157.    }
  158.    isArray = array;
  159. }
  160.  
  161. OtclAttributeTemplate::~OtclAttributeTemplate ()
  162. {
  163.    if (initialiser != NULL)
  164.    {
  165.       free (initialiser);
  166.    }
  167. }
  168.  
  169. OtclAttribute *OtclAttributeTemplate::instantiate (Tcl_Interp *interp, 
  170.                                                    Tcl_HashEntry *hashEntry)
  171. {
  172.    return new OtclAttribute(hashEntry,isArray,initialiser,interp);
  173. }
  174.